package com.besttone.model;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.besttone.common.StaticConstantType;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

public class BstShortlinkRequest extends Model<BstShortlinkRequest> {
    private static Log _log = LogFactory.getLog(BstShortlinkRequest.class);
    public static BstShortlinkRequest dao = new BstShortlinkRequest();

    public Page<BstShortlinkRequest> getNotSyncData(int pageNumber) {
	String select = "select h.id as id,h.shortCode as short_code,h.userAgent as client_browser,h.ip as client_ip,h.createTime as client_browse_time,h.phone as client_phone";
	String sqlExceptSelect = " from bst_shortlink_request h where h.is_sync="
		+ StaticConstantType.IS_NOT_SYNC;
	return dao.use("bstDB").paginate(pageNumber, 10, select,
		sqlExceptSelect);
    }

    /**
     * wide column
     * 
     * @param pageNumber
     * @return
     */
    public Page<Record> getNotSyncWideData(int pageNumber) {
	String select = "select " + "h.id as cust_id,"
		+ "h.shortCode as short_code,"
		+ "h.userAgent as client_browser," + "h.ip as client_ip,"
		+ "h.createTime as client_browse_time,"
		+ "h.phone as client_phone," + "h.source as request_source,"
		+ "s.flag as shortlink_flag," + "s.once as shortlink_once,"
		+ "s.longURL as shortlink_longurl,"
		+ "s.cookie as shortlink_cookie," + "b.custCode as cust_code,"
		+ "b.flag as business_flag,"
		+ "b.templateCode as template_code,"
		+ "b.businessPhone as business_phone";
	String sqlExceptSelect = " from bst_shortlink_request h,bst_shortlink s,bst_businessbinding b where h.shortCode=s.shortCode and h.shortCode=b.shortCode and h.is_sync="
		+ StaticConstantType.IS_NOT_SYNC;
	return Db.use("bstDB")
		.paginate(pageNumber, 10, select, sqlExceptSelect);
    }

}
